#
#  tarjanTextContainer.py
#  Tarjan
#
#  Created by Anders Hellerup Madsen on 7/28/08.
#  Copyright (c) 2008 __MyCompanyName__. All rights reserved.
#

from objc import YES, NO
from Foundation import *
from AppKit import *

class tarjanTextContainer(NSTextContainer):

    """Simple overide of textContainer that wraps text around a subview positioned at 0,0"""

    def isSimpleRectangularTextContainer(self):
        return NO

    def lineFragmentRectForProposedRect_sweepDirection_movementDirection_remainingRect_(self, rect, sweep, movement, remaining):

        textview = self.textView()
        if not self.textView():
            return (NSZeroRect, NSZeroRect)

        bounds = textview.bounds()
        subview_rect = textview.subviews()[0].frame()

        if not NSIntersectsRect(rect, subview_rect):
            return super(tarjanTextContainer, self).lineFragmentRectForProposedRect_sweepDirection_movementDirection_remainingRect_(rect, sweep, movement, remaining)

        x = bounds.origin.x + subview_rect.size.width
        w = bounds.size.width - x
        
        res = NSMakeRect(x, rect.origin.y, w, rect.size.height)

        return (res, NSZeroRect) # return 'remainingRect' parameter as second part of tuple


